<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>修改订单</title>
<!--公共样式开始-->
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/reset.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/common.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Plugins/FontAwesome/css/font-awesome.min.css">
<!--公共样式结束-->
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/module_form.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/page_memberAdd.css">
<script src="{$NOW_THEME_URL}/Assets/Js/jquery.min.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Js/jquery.timer.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Js/common.js"></script>
<script src="__PUBLIC__/Plugins/Datepicker/WdatePicker.js"></script>
<style>
.attr{
	margin-left:30px;
}
.editbtn{
	background-color:#339900;
	color:#FFFFFF;
	padding:2px 4px;
	cursor:pointer;
}
.entitle{
	font-size:16px;
	font-weight:bold;
	display:inline-block;
	width:120px;
}
.attr_list{
	/*background-color:green;
	color:#FFFFFF;*/
	margin-right:15px;
}
.attr_tr{
	background:#FF9933;
	color:#FFFFFF;
}
.delPro{
	background-color:#FF6600;
	color:#FFFFFF;
	padding:3px 7px;
	cursor:pointer;
}
.tianjia{
	float:right;
	background-color:#339900;
	color:#FFFFFF;
	padding:3px 7px;
	cursor:pointer;
	margin:5px 20px 5px;
}
</style>
</head>

<body>
<div class="mask"></div>
	<div class="page_header">
		<div class="tabbar">
			<ul class="tab clearfix" tabname="tab1">
				<li class="tabhover" show="tab1_0">配送信息</li>
				<li show="tab1_1">商品信息</li>
				<li show="tab1_2">备注信息</li>
			</ul>
		</div>
	</div>
	<div class="page_wraper">
	<form method="post" id="memberAdd_form" action="{:U('Order/edit')}" >
		<input type="hidden" id="id" name="id" value="{$id}">
		<div id="tab1_0" fortab="tab1">
			<table cellpadding="0" cellspacing="0" class="module_form" width="600">
				<tr>
					<td class="ele_title"><label for="cardnum">收货人：<em>*</em></label></td>
					<td class="ele_content" colspan="3">
						<input name="username" value="{$detail.username}" type="text" id="title" class="form_ele_text width_200">
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="cardnum">电话：<em>*</em></label></td>
					<td class="ele_content" colspan="3">
						<input name="mobile" value="{$detail.mobile}" type="text" id="entitle" class="form_ele_text width_200">
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="realname">收货地址：<em>*</em></label></td>
					<td class="ele_content" colspan="3">
						<input name="address" value="{$detail.address}" type="text" id="tel" class="form_ele_text width_400">
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="realname">中文地址：</label></td>
					<td class="ele_content" colspan="3">
						<notempty name='detail.cnaddress'>
							<input name="cnaddress" value="{$detail.cnaddress}" type="text" id="tel" class="form_ele_text width_400" 
						placeholder="如果是英文地址，请翻译成中文地址以便配送员准确送达">
						<else />
							<input name="cnaddress" value="{$address.address}" type="text" id="tel" class="form_ele_text width_400" 
						placeholder="如果是英文地址，请翻译成中文地址以便配送员准确送达">
						</notempty>
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="realname">客人备注：</label></td>
					<td class="ele_content" colspan="3">
						<input name="content" value="{$detail.content}" type="text" id="tel" class="form_ele_text width_400" 
						placeholder="请输入订单备注内容">
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="realname">客服备注：</label></td>
					<td class="ele_content" colspan="3">
						<input name="remark" value="{$detail.remark}" type="text" id="tel" class="form_ele_text width_400" 
						placeholder="请输入订单备注内容">
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="realname">所属餐厅：</label></td>
					<td class="ele_content" >{$outlet.title}</td>
					<td class="ele_title"><label for="sex">餐厅特别说明：</label></td>
					<td class="ele_content">{$outlet.information}</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="realname">订单编号：</label></td>
					<td class="ele_content" >{$detail.orderno}
						<eq name="detail.isyuding" value="1">（预订单）</eq>
					</td>
					<td class="ele_title"><label for="sex">订单状态：</label></td>
					<td class="ele_content">{$detail.status|get_array_key='ORDER_STATUS',###}</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="phone">下单时间：</label></td>
					<td class="ele_content">{$detail.addtime|date="Y-m-d H:i:s",###}</td>
					<td class="ele_title"><label for="phone">配送时间：</label></td>
					<td class="ele_content" colspan="3">
						<input type="text" class="form_ele_text" name="sdltime" value="{$detail.sdltime|date='Y-m-d H:i:s',###}" style="width:150px" onfocus="WdatePicker({dateFmt:'yyyy-M-d H:mm:ss'})">-
						<input type="text" class="form_ele_text" name="edltime" value="{$detail.edltime|date='Y-m-d H:i:s',###}" style="width:150px" onfocus="WdatePicker({dateFmt:'yyyy-M-d H:mm:ss'})">
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="phone">需要发票：</label></td>
					<td class="ele_content">
						<eq name="detail.isinvoice" value="1">
							<input type="text" class="form_ele_text" name="invoice_title" value="{$detail.invoice_title}">
						<else />
							否
						</eq>
					</td>
					<td class="ele_title"><label for="phone">需要确认：</label></td>
					<td class="ele_content" colspan="3">
						<eq name="detail.isconfirm" value="1">是<else />否</eq>
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="realname">菜品金额：</label></td>
					<td class="ele_content">￥{$detail.dishesfee}</td>
					<td class="ele_title"><label for="realname">酒水金额：</label></td>
					<td class="ele_content">￥{$detail.drinkfee}</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="sex">服务费：</label></td>
					<td class="ele_content">
						￥{$detail.shipfee}
						<!--<input type="text" name="shipfee" value="{$detail.shipfee}" class="form_ele_text width_200">-->
					</td>
					<td class="ele_title"><label for="sex">优惠金额：</label></td>
					<td class="ele_content">￥{$detail.cardfee}</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="iccard">实付金额：</label></td>
					<td class="ele_content">￥{$detail.orderfee}</td>
					<td class="ele_title"><label for="iccard">结算金额：</label></td>
					<td class="ele_content">￥{$detail.settlefee}</td>
				</tr>
				<tr>
					
						<td class="ele_title"><label for="iccard">赠送的饮料：</label></td>
						<td class="ele_content">
							<!-- <volist name="sdrink" id="v"><eq name="key" value="$detail.isdrink">{$v['zh-cn']}</eq></volist> -->
							<volist name="sdrink" id="v">
								<input type="radio" name="isdrink" value="{$key}" <eq name="key" value="$detail.isdrink">checked</eq>>{$v['zh-cn']}&nbsp;&nbsp;&nbsp;
							</volist>
						</td>
						<td class="ele_title"><label for="iccard">手工结算金额：</label></td>
						<td class="ele_content">
							<input type="text" class="form_ele_text" name="rsettlefee" id="rsettlefee" value="{$detail.rsettlefee}">
						</td>
				</tr>
				<tr>
					<td colspan="4" style="height:30px;"></td>
				</tr>
			</table>
		</div>
		<div id="tab1_1" fortab="tab1" class="clearfix" style="display:none;">
			<table cellpadding="0" cellspacing="0" class="module_form" width="600">
				<tr>
					<td colspan="8">&nbsp;</td>
					<td style="line-height:1.6;">
						<span class="tianjia" id="adddrink">添加饮品</span>
						<span class="tianjia" id="adddishes">添加菜品</span>
					</td>
				</tr>
				<tr>
					<td class="ele_title">商品编号</td>
					<td></td>
					<td class="ele_title">商品名称</td>
					<td class="ele_title">商品单价</td>
					<td class="ele_title">购买数量</td>
					<td class="ele_title">小计</td>
					<td class="ele_title">商品备注</td>
					<td class="ele_title" width="7%">&nbsp;</td>
					<td>操作</td>
				</tr>
				<volist name="dlist" id="v">
					<input type="hidden" id="orderno" name="orderno" value="{$v.orderno}" />
					<input type="hidden" id="orderid" name="orderid" value="{$v.id}" />
					<tr class="" style="line-height:20px">
						<td class="">{$v.pno}</td>
						<td class="fj_ico">
							<notempty name='v.information'>
								<i class=" icon-caret-down" style="cursor:pointer;"></i>
								<div class="fj_content">{$v.information}</div>
							<else />&nbsp;</notempty>
						</td>
						<td class="">{$v.title}<br/>{$v.entitle}</td>
						<td class="">￥{$v.price}</td>
						
						<td class="">
								<input type="text" name="amount[{$v.id}]" value="{$v.amount}" style="width:50px;text-align:center" class="form_ele_text amount"
								 orderno="{$detail.orderno}" dataid="{$detail.dataid}" detailid="{$v.id}" price="{$v.price}">
						</td>
						<td class="">￥{$v.total}</td>
						<td class=""><input type="text" name="ask[{$v.id}]" value="{$v.ask}" style="width:100px;"  class="form_ele_text"></td>
						<notempty name="v.detail.gnfr">
							<td class="editAttr" css="isshow" id="{$v.id}" must="{$v.detail.must}" ><span class="editbtn">{$v['detail']['must']}显示属性</span></td>
						<else />
							<td>&nbsp;</td>
						</notempty>
						<td>
							<a id="{$v.id}" class="delPro">删除</a>
						</td>
					</tr>
					<tr id="tr_{$v.id}" style="display:none">
						<td colspan="9">
							<foreach name="v.detail.gnfr" item="va" key="a">
								<div class="attr"><span class="entitle">{$va.title}：</span>
								<input type="hidden" name="flag[{$v.id}][{$a}][entitle]" value="{$va.entitle}" />
								<input type="hidden" name="flag[{$v.id}][{$a}][title]"   value="{$va.title}" />
								<input type="hidden" name="flag[{$v.id}][{$a}][xtype]"   value="{$va.type}" />
										<foreach name="va.config" item="vb" key="b">
											
											<span class="attr_list" >
												<eq name="va.type" value="1">
													<span class="kx1 selectRadio{$a}{$v.id}" pid="{$v.id}" entitle="{$vb.entitle}" title="{$vb.title}" num="{$vb.dnum}" price="{$vb.mprice}" mprice="{$vb.psprice}" key="{$a}" keys="{$b}">

														<input type="radio" name="must{$a}{$v.id}" <notempty name="v['attr'][$a]['config'][$b]">checked</notempty> >{$vb.title}/{$vb.entitle}
														<notempty name="vb.mprice">( ￥{$vb.mprice} )</notempty>
														
														<input type="hidden"   name="flag[{$v.id}][{$a}][config][{$b}][title]"   id="ktitle{$a}{$b}{$v.id}"    value=""/>
														<input type="hidden"   name="flag[{$v.id}][{$a}][config][{$b}][entitle]" id="kentitle{$a}{$b}{$v.id}"  value=""/>
														<input type="hidden"   name="flag[{$v.id}][{$a}][config][{$b}][mprice]"  id="kprice{$a}{$b}{$v.id}"    value=""/>
														<input type="hidden"   name="flag[{$v.id}][{$a}][config][{$b}][amprice]" id="kaprice{$a}{$b}{$v.id}"    value=""/>
														<input type="hidden"   name="flag[{$v.id}][{$a}][config][{$b}][num]"     id="knum{$a}{$b}{$v.id}"      value=""/>
													</span>
												</eq>
												<eq name="va.type" value="2">
													<span class="kx2 selectCheck{$a}{$v.id} checkRadio" pid="{$v.id}" entitle="{$vb.entitle}" title="{$vb.title}" num="{$v['attr'][$a]['config'][$b]['num']}" price="{$vb.mprice}" mprice="{$vb.psprice}" key="{$a}" keys="{$b}">
														<input type="checkbox" name="check{$a}{$v.id}[]" <notempty name="v['attr'][$a]['config'][$b]">checked</notempty> >{$vb.title}/{$vb.entitle}
															<notempty name="vb.mprice">( ￥{$vb.mprice} )</notempty>
														<select id="xz{$a}{$b}{$v.id}" >
															<for start="1" end="$vb.maxnum" >
																<option value="{$i}"
																<eq name="v['attr'][$a]['config'][$b]['num']" value="$i">selected</eq> >{$i}</option>
															</for>
														</select>
														<input type="hidden"   name="flag[{$v.id}][{$a}][config][{$b}][title]"   id="ctitle{$a}{$b}{$v.id}"   />
														<input type="hidden"   name="flag[{$v.id}][{$a}][config][{$b}][entitle]" id="centitle{$a}{$b}{$v.id}" />
														<input type="hidden"   name="flag[{$v.id}][{$a}][config][{$b}][mprice]"  id="cprice{$a}{$b}{$v.id}"   />
														<input type="hidden"   name="flag[{$v.id}][{$a}][config][{$b}][amprice]" id="caprice{$a}{$b}{$v.id}"   />
														<input type="hidden"   name="flag[{$v.id}][{$a}][config][{$b}][num]"     id="cnum{$a}{$b}{$v.id}"     />
													</span>
												</eq>
											</span>
											
									    </foreach>
									    
									    
								</div>
							</foreach>
						</td>
					</tr>
				</volist>
				
				<!--<tr>
					<td colspan="7" style="height:30px;"></td>
				</tr>-->
			</table>
		</div>
		<div id="tab1_2" fortab="tab1" class="clearfix" style="display:none;">
			<div style="height:20px;">
				<span class="tianjia" id="tianjia">添加备注</span>
			</div>
			<table cellpadding="0" cellspacing="0" class="module_form" width="600">
				<tr>
					<td class="ele_title">备注内容</td>
					<td class="ele_title">备注金额</td>
					<td class="ele_title">计算规则</td>
					<td class="ele_title">操作时间</td>
					<td class="ele_title">操作</td>
				</tr>
				<volist name="blist" id="v">
					<tr>
						<td class="">{$v.remark}</td>
						<td class="">{$v.price}</td>
						<td class="">
							<notempty name="v.price">
								<eq name="v.opera" value="plus">加<else />减</eq>
							<else />
								与金额无关
							</notempty>
						</td>
						<td class="">{$v.addtime|date="Y-m-d H:i:s",###}</td>
						<td class="">
							<span class="tianjia dealBak" ordid="{$detail.id}" dataid="{$v.id}">删除</span>
						</td>
					</tr>
				</volist>
			</table>
		</div>
		</form>
	</div>
	<div class="page_footer pdtd10">
		<input type="button" name="submit" id="submit" value="提交数据"  class="form_ele_submit"/>
		<input type="reset"  name="reset"  id="reset"   value="清空数据"  class="form_ele_reset"/>
	</div>
</body>
<script type="text/javascript">
	$('.fj_ico i').on('click',function(){
		$(this).siblings('.fj_content').show();
		$('.mask').show();
	});
	$('.mask').on('click',function(){
			$('.fj_content').hide();
			$(this).hide();
	});

	//弹出窗口全局变量
	var api = frameElement.api, W = api.opener;
	$(function(){
		//滑动门
		$('.tabbar li').click(function(){
			var tabname = $('.tabbar>ul').attr('tabname');
			$('.tabbar li').removeClass('tabhover');
			$(this).addClass('tabhover');
			
			$('div[fortab="'+tabname+'"]').hide();
			$('#'+$(this).attr('show')).show();
		});
		
		//表格隔行换色
		$('.module_form tr:odd').addClass('odd');
		$('.module_form tr:even').addClass('even');
	
		//重置
		$('.form_ele_reset').on('click',function(){
			$('#memberAdd_form').get(0).reset();
		});

		//修改菜品数量，异步更新
		$('.amount').change(function(){
			var obj      = $(this);
			var amount   = obj.val();
			var detailid = obj.attr('detailid');
			var dataid   = obj.attr('dataid');
			var orderno  = obj.attr('orderno');
			var price    = obj.attr('price');
			var editnum  = 1;
			var total    = price*amount;
			    total    = total.toFixed(2); 
			
			//return;
			if(amount<=0 || isNaN(amount)){
				windowApi.lhgdialog.alert('请输入正整数');return;
			}
			
			$.post("{:U('Order/edit')}",{amount:amount,detailid:detailid,dataid:dataid,orderno:orderno,editnum:editnum},function(data){
				if(data.status==1){
					obj.parent('td').next('td').text('￥'+total);
				}else{
					windowApi.lhgdialog.alert(data.info);
				}
			});
		});
		
		//添加菜品到订单
		$('#adddishes').on('click',function(){
			var restid = "{$detail.outletid}";
			var orderno = "{$detail.orderno}";
			var href   = "{:U('Product/index','editorder=1')}&id="+restid+"&orderno="+orderno;
			var width  = '1100px';
			var height = '530px';
			var title  = '选择菜品';
			openDialog('Product_index',href,width,height,title);
		});

		//删除某条备注
		$('.dealBak').on('click',function(){
			var ordid   = $(this).attr('ordid');
			var dataid  = $(this).attr('dataid');
			var msg     = "确认删除该备注内容吗？";
			var obj     = $(this);
			
			windowApi.lhgdialog.confirm(msg, function(){
				$.post("{:U('Order/edit')}",{ordid:ordid,dataid:dataid,dealbak:1},function(data){
					if(data.status==1){
						obj.parent('td').parent('tr').remove();
					}else{
						windowApi.lhgdialog.alert(data.info);
					}
				});
			});
		});
		
		//添加饮品到订单
		$('#adddrink').on('click',function(){
			var restid  = "{$detail.outletid}";
			var orderno = "{$detail.orderno}";
			var cityid  = "{$detail.city}";
			var href    = "{:U('Product/drink','editorder=1')}&id="+restid+"&orderno="+orderno+"&cityid="+cityid;
			var width   = '1100px';
			var height  = '530px';
			var title   = '选择饮品';
			openDialog('Product_drink',href,width,height,title);
		});
		
		//添加备注
		$('#tianjia').on('click',function(){
			var id     = "{$detail.id}";
			var href   = "{:U('Order/orderbak')}&id="+id;
			var width  = '520px';
			var height = '260px';
			var title  = '订单备注';
			openDialog('Order_orderbak',href,width,height,title);
		});
		
		//删除某条商品数据
		$('.delPro').on('click',function(){
			var id  = $(this).attr("id");
			var oid = "{$detail.id}";
			var obj = $(this);
			var msg = "确认删除该商品吗？";
			
			windowApi.lhgdialog.confirm(msg, function(){
				$.get("{:U('Order/delProduct')}",{id:id,oid:oid},function(data){
					if(data.status==1){
						obj.parents('tr').remove();
					}else{
						alert(data.info);return;
					}
				});
			},function(){return;});
		});
		
		//
		$(".form_ele_submit").on("click",function(){
			
			var postData = {};
			var tipsObj = windowApi.lhgdialog.tips('正在提交数据...',10,etIcon.loading);
			
			postData = $("#memberAdd_form").serialize();
			$.post("{:U('Order/edit')}", postData ,function(d){
				if(d.status==1){
					tipsObj.close();
					windowApi.lhgdialog.tips('数据修改成功！',1,etIcon.success,function(){
						frameApi.close(); //关闭当前窗口
						var obj = windowApi.lhgdialog.list['Order_index'];
						obj.reload(obj);
					});
				}else{
					windowApi.lhgdialog.alert("修改失败");
				}
			}, "json");
		});
		
		//显示隐藏属性
		$(".editAttr").click(function(){
			var id   = $(this).attr("id");
			var css  = $(this).attr("css");
			var must = $(this).attr("must");
			
			if(css=="isshow"){
				$("#tr_"+id).show();
				$("#tr_"+id).prev('tr').removeClass("even odd");
				$("#tr_"+id).prev('tr').addClass("attr_tr");
				$(this).attr("css","ishide");
				$(this).children("span").text(must+"隐藏属性");
			}else{
				$("#tr_"+id).hide();
				$("#tr_"+id).prev('tr').removeClass("attr_tr");
				$(this).attr("css","isshow");
				$(this).children("span").text(must+"显示属性");
			}
		});
		
		$(".kx1").each(function(i){
			var key      = $(this).attr("key");
			var keys     = $(this).attr("keys");
			var id       = $(this).attr("pid");
			var title    = $(this).attr("title");
			var entitle  = $(this).attr("entitle");
			var num      = $(this).attr("num");
			var price    = $(this).attr("price");
			var mprice   = $(this).attr("mprice");
			var obj = $(this).children("input[type=radio]").attr("checked");
			if(obj){
				$("#ktitle"+key+keys+id).val(title);
				$("#kentitle"+key+keys+id).val(entitle);
				$("#knum"+key+keys+id).val(num);
				$("#kprice"+key+keys+id).val(price);
				$("#kaprice"+key+keys+id).val(mprice);
			}
			
			$(this).children("input[type=radio]").on("click",function(){
				$('.selectRadio'+key+id).each(function(){
					 $(this).children("input[type=hidden]").val("");
				 })
				 
				if($(this).attr("checked")){
					$("#ktitle"+key+keys+id).val(title);
					$("#kentitle"+key+keys+id).val(entitle);
					$("#knum"+key+keys+id).val(num);
					$("#kprice"+key+keys+id).val(price); 
					$("#kaprice"+key+keys+id).val(mprice); 
				}
			});
		});
		
		$(".kx2").each(function(j){
			var title   = $(this).attr("title");
			var entitle = $(this).attr("entitle");
			var price   = $(this).attr("price");
			var mprice  = $(this).attr("mprice");
			var key     = $(this).attr("key");
			var keys    = $(this).attr("keys");
			var id      = $(this).attr("pid");
			var num     = $(this).attr("num");
			var obj     = $(this).children("input[type=checkbox]").attr("checked");
			if(obj){
				$("#ctitle"+key+keys+id).val(title);
				$("#centitle"+key+keys+id).val(entitle);
				$("#cnum"+key+keys+id).val(num);
				$("#cprice"+key+keys+id).val(price);
				$("#caprice"+key+keys+id).val(mprice);
			}
			
			$("#xz"+key+keys+id).live('change',function(){
				$("#cnum"+key+keys+id).val($(this).val());
			});
			
			$(this).find("input[type=checkbox]").live('click',function(){
				console.log($(this).prop("checked"));
				if($(this).prop("checked")){
					$("#ctitle"+key+keys+id).val(title);
					$("#centitle"+key+keys+id).val(entitle);
					$("#cprice"+key+keys+id).val(price);
					$("#caprice"+key+keys+id).val(mprice);
					$("#cnum"+key+keys+id).val(num);
				}else{
					$("#ctitle"+key+keys+id).val('');
					$("#centitle"+key+keys+id).val('');
					$("#cprice"+key+keys+id).val('');
					$("#caprice"+key+keys+id).val('');
					$("#cnum"+key+keys+id).val('');
					$("#xz"+key+keys+id).val('');
				}
			});
		});
	});
</script>
</html>
